/*
========================================================================
 Name        : SPDLifeServiceContainer.cpp
 Author      : 
 Copyright   : Your copyright notice
 Description : 
========================================================================
*/
// [[[ begin generated region: do not modify [Generated System Includes]
#include <barsread.h>
#include <eikimage.h>
#include <eikenv.h>
#include <stringloader.h>
#include <eiklabel.h>
#include <aknviewappui.h>
#include <eikappui.h>
#include <akniconutils.h>
#include <weather.mbg>
#include <SPD.rsg>
// ]]] end generated region [Generated System Includes]

// [[[ begin generated region: do not modify [Generated User Includes]
#include "SPDLifeServiceContainer.h"
#include "SPDLifeServiceContainerView.h"
#include "SPD.hrh"
// ]]] end generated region [Generated User Includes]

// [[[ begin generated region: do not modify [Generated Constants]
_LIT( KweatherFile, "\\resource\\apps\\weather.mbm" );
// ]]] end generated region [Generated Constants]

/**
 * First phase of Symbian two-phase construction. Should not 
 * contain any code that could leave.
 */
CSPDLifeServiceContainer::CSPDLifeServiceContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	iWeatherBg = NULL;
	iCityLabel = NULL;
	iOtherCityButton = NULL;
	iTodayDate = NULL;
	iTodayIcon = NULL;
	iTodayWeather = NULL;
	iTomorrowDate = NULL;
	iTomorrowIcon = NULL;
	iTomorrowWeather = NULL;
	iThirdDate = NULL;
	iThirdIcon = NULL;
	iThirdWeather = NULL;
	iFourthDate = NULL;
	iFourthIcon = NULL;
	iFourthWeather = NULL;
	iFifthDate = NULL;
	iFifthIcon = NULL;
	iFifthWeather = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
/** 
 * Destroy child controls.
 */
CSPDLifeServiceContainer::~CSPDLifeServiceContainer()
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	delete iWeatherBg;
	iWeatherBg = NULL;
	delete iCityLabel;
	iCityLabel = NULL;
	delete iOtherCityButton;
	iOtherCityButton = NULL;
	delete iTodayDate;
	iTodayDate = NULL;
	delete iTodayIcon;
	iTodayIcon = NULL;
	delete iTodayWeather;
	iTodayWeather = NULL;
	delete iTomorrowDate;
	iTomorrowDate = NULL;
	delete iTomorrowIcon;
	iTomorrowIcon = NULL;
	delete iTomorrowWeather;
	iTomorrowWeather = NULL;
	delete iThirdDate;
	iThirdDate = NULL;
	delete iThirdIcon;
	iThirdIcon = NULL;
	delete iThirdWeather;
	iThirdWeather = NULL;
	delete iFourthDate;
	iFourthDate = NULL;
	delete iFourthIcon;
	iFourthIcon = NULL;
	delete iFourthWeather;
	iFourthWeather = NULL;
	delete iFifthDate;
	iFifthDate = NULL;
	delete iFifthIcon;
	iFifthIcon = NULL;
	delete iFifthWeather;
	iFifthWeather = NULL;
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is not left on cleanup stack.
 * @param aRect bounding rectangle
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return initialized instance of CSPDLifeServiceContainer
 */
CSPDLifeServiceContainer* CSPDLifeServiceContainer::NewL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CSPDLifeServiceContainer* self = CSPDLifeServiceContainer::NewLC( 
			aRect, 
			aParent, 
			aCommandObserver );
	CleanupStack::Pop( self );
	return self;
	}

/**
 * Construct the control (first phase).
 *  Creates an instance and initializes it.
 *  Instance is left on cleanup stack.
 * @param aRect The rectangle for this window
 * @param aParent owning parent, or NULL
 * @param aCommandObserver command observer
 * @return new instance of CSPDLifeServiceContainer
 */
CSPDLifeServiceContainer* CSPDLifeServiceContainer::NewLC( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	CSPDLifeServiceContainer* self = new ( ELeave ) CSPDLifeServiceContainer();
	CleanupStack::PushL( self );
	self->ConstructL( aRect, aParent, aCommandObserver );
	return self;
	}
			
/**
 * Construct the control (second phase).
 *  Creates a window to contain the controls and activates it.
 * @param aRect bounding rectangle
 * @param aCommandObserver command observer
 * @param aParent owning parent, or NULL
 */ 
void CSPDLifeServiceContainer::ConstructL( 
		const TRect& aRect, 
		const CCoeControl* aParent, 
		MEikCommandObserver* aCommandObserver )
	{
	if ( aParent == NULL )
	    {
		CreateWindowL();
	    }
	else
	    {
	    SetContainerWindowL( *aParent );
	    }
	iFocusControl = NULL;
	iCommandObserver = aCommandObserver;
	InitializeControlsL();
	SetRect( aRect );
	ActivateL();
	// [[[ begin generated region: do not modify [Post-ActivateL initializations]
	// ]]] end generated region [Post-ActivateL initializations]
	
	}
			
/**
* Return the number of controls in the container (override)
* @return count
*/
TInt CSPDLifeServiceContainer::CountComponentControls() const
	{
	return ( int ) ELastControl;
	}
				
/**
* Get the control with the given index (override)
* @param aIndex Control index [0...n) (limited by #CountComponentControls)
* @return Pointer to control
*/
CCoeControl* CSPDLifeServiceContainer::ComponentControl( TInt aIndex ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	switch ( aIndex )
		{
		case EWeatherBg:
			return iWeatherBg;
		case ECityLabel:
			return iCityLabel;
		case EOtherCityButton:
			return iOtherCityButton;
		case ETodayDate:
			return iTodayDate;
		case ETodayIcon:
			return iTodayIcon;
		case ETodayWeather:
			return iTodayWeather;
		case ETomorrowDate:
			return iTomorrowDate;
		case ETomorrowIcon:
			return iTomorrowIcon;
		case ETomorrowWeather:
			return iTomorrowWeather;
		case EThirdDate:
			return iThirdDate;
		case EThirdIcon:
			return iThirdIcon;
		case EThirdWeather:
			return iThirdWeather;
		case EFourthDate:
			return iFourthDate;
		case EFourthIcon:
			return iFourthIcon;
		case EFourthWeather:
			return iFourthWeather;
		case EFifthDate:
			return iFifthDate;
		case EFifthIcon:
			return iFifthIcon;
		case EFifthWeather:
			return iFifthWeather;
		}
	// ]]] end generated region [Generated Contents]
	
	// handle any user controls here...
	
	return NULL;
	}
				
/**
 *	Handle resizing of the container. This implementation will lay out
 *  full-sized controls like list boxes for any screen size, and will layout
 *  labels, editors, etc. to the size they were given in the UI designer.
 *  This code will need to be modified to adjust arbitrary controls to
 *  any screen size.
 */				
void CSPDLifeServiceContainer::SizeChanged()
	{
	CCoeControl::SizeChanged();
	LayoutControls();
	// [[[ begin generated region: do not modify [Generated Contents]
			
	// ]]] end generated region [Generated Contents]
	
	}
				
// [[[ begin generated function: do not modify
/**
 * Layout components as specified in the UI Designer
 */
void CSPDLifeServiceContainer::LayoutControls()
	{
	iWeatherBg->SetExtent( TPoint( 26, 50 ), TSize( 308, 369 ) );
	iCityLabel->SetExtent( TPoint( 40, 63 ), TSize( 60, 34 ) );
	iTodayDate->SetExtent( TPoint( 40, 123 ), TSize( 97, 26 ) );
	iTodayIcon->SetExtent( TPoint( 148, 24 ), TSize( 64, 64 ) );
	iTodayWeather->SetExtent( TPoint( 200, 125 ), TSize( 123, 26 ) );
	iTomorrowDate->SetExtent( TPoint( 40, 183 ), TSize( 97, 26 ) );
	iTomorrowIcon->SetExtent( TPoint( 160, 175 ), TSize( 40, 40 ) );
	iTomorrowWeather->SetExtent( TPoint( 200, 183 ), TSize( 123, 26 ) );
	iThirdDate->SetExtent( TPoint( 40, 243 ), TSize( 97, 26 ) );
	iThirdIcon->SetExtent( TPoint( 160, 235 ), TSize( 40, 40 ) );
	iThirdWeather->SetExtent( TPoint( 200, 243 ), TSize( 123, 26 ) );
	iFourthDate->SetExtent( TPoint( 40, 303 ), TSize( 97, 26 ) );
	iFourthIcon->SetExtent( TPoint( 160, 295 ), TSize( 40, 40 ) );
	iFourthWeather->SetExtent( TPoint( 200, 303 ), TSize( 123, 26 ) );
	iFifthDate->SetExtent( TPoint( 40, 363 ), TSize( 97, 26 ) );
	iFifthIcon->SetExtent( TPoint( 160, 355 ), TSize( 40, 40 ) );
	iFifthWeather->SetExtent( TPoint( 200, 363 ), TSize( 123, 26 ) );
	}
// ]]] end generated function

/**
 *	Handle key events.
 */				
TKeyResponse CSPDLifeServiceContainer::OfferKeyEventL( 
		const TKeyEvent& aKeyEvent, 
		TEventCode aType )
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	
	// ]]] end generated region [Generated Contents]
	
	if ( iFocusControl != NULL
		&& iFocusControl->OfferKeyEventL( aKeyEvent, aType ) == EKeyWasConsumed )
		{
		return EKeyWasConsumed;
		}
	return CCoeControl::OfferKeyEventL( aKeyEvent, aType );
	}
				
// [[[ begin generated function: do not modify
/**
 *	Initialize each control upon creation.
 */				
void CSPDLifeServiceContainer::InitializeControlsL()
	{
	iWeatherBg = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWeatherback, EMbmWeatherWeatherback_mask );
		AknIconUtils::SetSize( bitmap, TSize( 308, 369 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 308, 369 ), EAspectRatioPreserved );
		iWeatherBg->SetPicture( bitmap, mask );
		}
	iWeatherBg->SetAlignment( EHCenterVTop );
	iCityLabel = new ( ELeave ) CEikLabel;
	iCityLabel->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_CITY_LABEL );
		iCityLabel->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	
	iOtherCityButton = static_cast< CAknButton* >
					( EikControlFactory::CreateByTypeL( EAknCtButton ).iControl );
	iOtherCityButton->ConstructFromResourceL ( R_SPDLIFE_SERVICE_CONTAINER_OTHER_CITY_BUTTON );
	
	iOtherCityButton->SetContainerWindowL ( *this );
	iOtherCityButton->SetRect ( TRect ( 
								TPoint ( 210, 60 ) , 
								TSize ( 107, 46 ) )  
								 ) ; 
	iOtherCityButton->SetObserver( ( MCoeControlObserver* ) iCommandObserver ); 
	
	
	
	
	
	
	iTodayDate = new ( ELeave ) CEikLabel;
	iTodayDate->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_TODAY_DATE );
		iTodayDate->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iTodayIcon = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWheather10, EMbmWeatherWheather10_mask );
		AknIconUtils::SetSize( bitmap, TSize( 64, 64 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 64, 64 ), EAspectRatioPreserved );
		iTodayIcon->SetPicture( bitmap, mask );
		}
	iTodayIcon->SetAlignment( EHCenterVTop );
	iTodayWeather = new ( ELeave ) CEikLabel;
	iTodayWeather->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_TODAY_WEATHER );
		iTodayWeather->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iTomorrowDate = new ( ELeave ) CEikLabel;
	iTomorrowDate->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_TOMORROW_DATE );
		iTomorrowDate->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iTomorrowIcon = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWheather11, EMbmWeatherWheather11_mask );
		AknIconUtils::SetSize( bitmap, TSize( 40, 40 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 40, 40 ), EAspectRatioPreserved );
		iTomorrowIcon->SetPicture( bitmap, mask );
		}
	iTomorrowIcon->SetAlignment( EHCenterVTop );
	iTomorrowWeather = new ( ELeave ) CEikLabel;
	iTomorrowWeather->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_TOMORROW_WEATHER );
		iTomorrowWeather->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iThirdDate = new ( ELeave ) CEikLabel;
	iThirdDate->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_THIRD_DATE );
		iThirdDate->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iThirdIcon = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWheather08, EMbmWeatherWheather08_mask );
		AknIconUtils::SetSize( bitmap, TSize( 40, 40 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 40, 40 ), EAspectRatioPreserved );
		iThirdIcon->SetPicture( bitmap, mask );
		}
	iThirdIcon->SetAlignment( EHCenterVTop );
	iThirdWeather = new ( ELeave ) CEikLabel;
	iThirdWeather->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_THIRD_WEATHER );
		iThirdWeather->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iFourthDate = new ( ELeave ) CEikLabel;
	iFourthDate->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_FOURTH_DATE );
		iFourthDate->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iFourthIcon = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWheather09, EMbmWeatherWheather09_mask );
		AknIconUtils::SetSize( bitmap, TSize( 40, 40 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 40, 40 ), EAspectRatioPreserved );
		iFourthIcon->SetPicture( bitmap, mask );
		}
	iFourthIcon->SetAlignment( EHCenterVTop );
	iFourthWeather = new ( ELeave ) CEikLabel;
	iFourthWeather->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_FOURTH_WEATHER );
		iFourthWeather->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iFifthDate = new ( ELeave ) CEikLabel;
	iFifthDate->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_FIFTH_DATE );
		iFifthDate->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	iFifthIcon = new ( ELeave ) CEikImage;
		{
		CFbsBitmap *bitmap, *mask;
		AknIconUtils::CreateIconL( bitmap, mask,
				KweatherFile, EMbmWeatherWheather12, EMbmWeatherWheather12_mask );
		AknIconUtils::SetSize( bitmap, TSize( 40, 40 ), EAspectRatioPreserved );
		AknIconUtils::SetSize( mask, TSize( 40, 40 ), EAspectRatioPreserved );
		iFifthIcon->SetPicture( bitmap, mask );
		}
	iFifthIcon->SetAlignment( EHCenterVTop );
	iFifthWeather = new ( ELeave ) CEikLabel;
	iFifthWeather->SetContainerWindowL( *this );
		{
		TResourceReader reader;
		iEikonEnv->CreateResourceReaderLC( reader, R_SPDLIFE_SERVICE_CONTAINER_FIFTH_WEATHER );
		iFifthWeather->ConstructFromResourceL( reader );
		CleanupStack::PopAndDestroy(); // reader internal state
		}
	
	iOtherCityButton->SetFocus( ETrue );
	iFocusControl = iOtherCityButton;
	
	}
// ]]] end generated function

/** 
 * Handle global resource changes, such as scalable UI or skin events (override)
 */
void CSPDLifeServiceContainer::HandleResourceChange( TInt aType )
	{
	CCoeControl::HandleResourceChange( aType );
	SetRect( iAvkonViewAppUi->View( TUid::Uid( ESPDLifeServiceContainerViewId ) )->ClientRect() );
	//SetRect( iAvkonViewAppUi->ApplicationRect() );
	// [[[ begin generated region: do not modify [Generated Contents]
	// ]]] end generated region [Generated Contents]
	
	}
				
/**
 *	Draw container contents.
 */				
void CSPDLifeServiceContainer::Draw( const TRect& aRect ) const
	{
	// [[[ begin generated region: do not modify [Generated Contents]
	CWindowGc& gc = SystemGc();
	gc.SetPenStyle( CGraphicsContext::ENullPen );
	TRgb backColor( 214,227,250 );
	gc.SetBrushColor( backColor );
	gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
	gc.DrawRect( aRect );
	
	// ]]] end generated region [Generated Contents]
	
	}
				
